package ${package_name}.web.controller;

import ${package_name}.common.entity.${table_name};
import ${package_name}.service.${table_name}Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package_name}.common.annotation.AutoLog;
import ${package_name}.common.annotation.ShiroDesc;
import ${package_name}.common.data.Result;
import ${package_name}.common.exception.AlertException;
import ${package_name}.common.utils.SysConst;
import ${package_name}.common.utils.SysUtils;
import ${package_name}.service.SysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Description: <br/>
 * ${table_annotation}
 * <p>
    * <br/>
    * @Auther: ${author}
    * @create ${date}
    */
    @RestController
    @RequestMapping("${sub_path}")
    public class ${table_name}Controller {

    /**
    * ${table_annotation}服务
    */
    @Autowired
    private ${table_name}Service ${table_name?uncap_first}Service;

    /**
    * 列表
    *
    * @return Result
    */
    @AutoLog
    @GetMapping("/list")
    @RequiresPermissions("${sub_permission}:list")
    @ShiroDesc("${table_annotation}:列表")
    public Result list() throws AlertException {
    return Result.ok().data(${table_name?uncap_first}Service.list(SysUtils.autoCnd(${table_name}.class)));
    }


    /**
    * 添加${table_annotation}
    *
    * @param
    * @return Result
    */
    @AutoLog
    @PostMapping
    @RequiresPermissions("${sub_permission}:add")
    @ShiroDesc("${table_annotation}:添加")
    public Result add(${table_name} ${table_name?uncap_first}) throws AlertException {
    boolean b = ${table_name?uncap_first}Service.save(${table_name?uncap_first});

    if (!b) {
    throw new AlertException("${table_annotation}添加失败");
    }

    return Result.ok("${table_annotation}添加成功");
    }


    /**
    * 获得指定id ${table_annotation}。
    *
    * @param
    * @return Result
    */
    @AutoLog
    @GetMapping("/{id}")
    @RequiresPermissions("${sub_permission}:look")
    @ShiroDesc("${table_annotation}:查看")
    public Result get(@PathVariable("id") String id) throws AlertException {
${table_name} ${table_name?uncap_first} = ${table_name?uncap_first}Service.getById(id);

    if (${table_name?uncap_first} == null) {
    throw new AlertException("未找到相关${table_annotation}信息");
    }

    return Result.ok().data(${table_name?uncap_first});
    }


    /**
    * 更新${table_annotation}
    *
    * @param
    * @return Result
    */
    @AutoLog
    @PutMapping
    @RequiresPermissions("${sub_permission}:save")
    @ShiroDesc("${table_annotation}:保存")
    public Result update(${table_name} ${table_name?uncap_first}) throws AlertException {
    boolean b = ${table_name?uncap_first}Service.updateById(${table_name?uncap_first});
    if (!b) {
    throw new AlertException("${table_annotation}更新失败");
    }

    return Result.ok("${table_annotation}更新成功");
    }


    /**
    * 删除${table_annotation}
    *
    * @param
    * @return Result
    */
    @AutoLog
    @DeleteMapping("/{id}")
    @RequiresPermissions("${sub_permission}:del")
    @ShiroDesc("${table_annotation}:删除")
    public Result delete(@PathVariable("id") String id) throws AlertException {
    boolean b = ${table_name?uncap_first}Service.removeById(id);

    if (!b) {
    throw new AlertException("${table_annotation}删除失败");
    }

    return Result.ok("删除${table_annotation}成功");
    }

    }
